package com.neu.niuyuchao.service;

import com.neu.commons.Dao.BaseDao;
import com.neu.niuyuchao.dao.StuInfoDaoImpl;
import com.neu.niuyuchao.util.ConvertUtil;
import com.neu.wangweili.dao.StuBatchDao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StuInfoService {
    private StuInfoDaoImpl stuInfoDao;
    public StuInfoService(){
        stuInfoDao=new StuInfoDaoImpl();

    }
    public Map<String,Object> doFind(String stu_no){
       Map<String,Object> params=null;
       List<Map<String,Object>> list=null;
       list=stuInfoDao.findStu(stu_no);
       if(list.size()>0){
           params=list.get(0);
       }
        return params;
    }
    public boolean doCommitApply(Map<String,String[]> params){
        boolean flag=false;
        Map<String,String> item=new HashMap<>();
        item=ConvertUtil.convert(params);
        int row=stuInfoDao.commitApply(item);
        if(row>0){
            flag=true;
        }
        return flag;
    }

    public boolean Allagree(String[] key) {
        boolean flag=false;
        StuBatchDao d=new StuBatchDao();
          int row=d.Allupdate(key);
        if (row>0){
            flag=true;
        }
        return  flag;
    }

    public Object[] insert(List<Map<String,String>> list) {

        Object[]obj=new Object[list.size()];
        int i=0;
        BaseDao d=new BaseDao();
        String sql= " select dor_id from t_dor_info "
                + " where dor_build=? and dor_no=? ";
        for (Map<String,String>map:list){
            List<Map<String, Object>> param=new ArrayList<>();
            String dor_build=map.get("dor_build");
            String dor_no=map.get("dor_no");
            Object o=d.BaseDaoBatchQuery(sql,dor_build,dor_no);
            obj[i]=o;
            i++;
        }
        return obj;
    }

    public boolean Allrut(String[] k) {
        boolean flag=false;
        StuBatchDao d=new StuBatchDao();
        int row=d.AllRUT(k);
        if (row>0){
            flag=true;
        }
        return  flag;
    }

    public int  UpdateStu(Object[] param,Object[] objects){
        int row=0;
        BaseDao d=new BaseDao();
        String sql="update t_stu_info"
                 +" set dor_id=? "
                 +" where stu_id=?";
        for (int i = 0; i <param.length ; i++) {
            row=d.BaseDaoUpdate(sql,param[i],objects[i]);
        }
        System.out.println(row);
        return row;
    }
}
